﻿//Keyboard hook by: Stephen Toub - MSFT  (Figured I would give credit here)

using System;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace Piyrez_LoL_Jungle_Timers
{
     static class Program
    {
        private const int WH_KEYBOARD_LL = 13;                          //KEYBOARD HOOK PIECE
        private const int WM_KEYDOWN = 0x0100;                          //KEYBOARD HOOK PIECE
        private static LowLevelKeyboardProc _proc = HookCallback;       //KEYBOARD HOOK PIECE
        private static IntPtr _hookID = IntPtr.Zero;                    //KEYBOARD HOOK PIECE

        // Timer Integers!
        public static int dTick;
        public static int bTick;
        public static int pgTick;
        public static int plTick;
        public static int bgTick;
        public static int blTick;


        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            _hookID = SetHook(_proc);  //KEYBOARD HOOK PIECE
            //Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new mainForm());
            UnhookWindowsHookEx(_hookID);  //KEYBOARD HOOK PIECE
        }



        //--------------------------- KEYBOARD HOOK PIECE
        private static IntPtr SetHook(LowLevelKeyboardProc proc)
        {
            using (Process curProcess = Process.GetCurrentProcess())
            using (ProcessModule curModule = curProcess.MainModule)
            {
                return SetWindowsHookEx(WH_KEYBOARD_LL, proc,
                    GetModuleHandle(curModule.ModuleName), 0);
            }
        }

        private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);

        private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
            {
                int vkCode = Marshal.ReadInt32(lParam);
                if ((Keys)vkCode == Keys.NumPad0) // Numpad0 Resets all timers
                {
                    dTick = 0;
                    bTick = 0;
                    pgTick = 0;
                    plTick = 0;
                    bgTick = 0;
                    blTick = 0;
                    mainForm.purpGolemTimer.Stop();
                    mainForm.purpGolemBar.Value = 0;
                    Overlay.olpurpGolemL.Text = "";
                    mainForm.purpLizardTimer.Stop();
                    mainForm.purpLizardBar.Value = 0;
                    Overlay.olpurpLizardL.Text = "";
                    mainForm.blueGolemTimer.Stop();
                    mainForm.blueGolemBar.Value = 0;
                    Overlay.olblueGolemL.Text = "";
                    mainForm.blueLizardTimer.Stop();
                    mainForm.blueLizardBar.Value = 0;
                    Overlay.olblueLizardL.Text = "";
                    mainForm.DragonTimer.Stop();
                    mainForm.DragonBar.Value = 0;
                    Overlay.olDragonL.Text = "";
                    mainForm.BaronTimer.Stop();
                    mainForm.BaronBar.Value = 0;
                    Overlay.olBaronL.Text = "";
                }
                if ((Keys)vkCode == Keys.NumPad1) // Numpad1 Starts the Blue Golem timer
                {
                    mainForm.blueGolemBar.Value = 0;
                    mainForm.blueGolemTimer.Enabled = true;
                    bgTick = 300;
                }
                if ((Keys)vkCode == Keys.NumPad2) // Numpad2 Starts the Blue Lizard timer
                {
                    mainForm.blueLizardBar.Value = 0;
                    mainForm.blueLizardTimer.Enabled = true;
                    blTick = 300;
                }
                if ((Keys)vkCode == Keys.NumPad3) // Numpad3 Starts the Dragon timer
                {
                    mainForm.DragonBar.Value = 0;
                    mainForm.DragonTimer.Enabled = true;
                    dTick = 360;
                }
                if ((Keys)vkCode == Keys.NumPad4) // Numpad4 Starts the Purple Golem timer
                {
                    mainForm.purpGolemBar.Value = 0;
                    mainForm.purpGolemTimer.Enabled = true;
                    pgTick = 300;
                }
                if ((Keys)vkCode == Keys.NumPad5) // Numpad5 Starts the Purple Lizard timer
                {
                    mainForm.purpLizardBar.Value = 0;
                    mainForm.purpLizardTimer.Enabled = true;
                    plTick = 300;
                }
                if ((Keys)vkCode == Keys.NumPad6) // Numpad6 Starts the Baron timer
                {
                    mainForm.BaronBar.Value = 0;
                    mainForm.BaronTimer.Enabled = true;
                    bTick = 420;
                }
                if ((Keys)vkCode == Keys.NumPad7) // Numpad "7" Announce TOP MIA to your team!
                {
                    //MessageBox.Show("TOP MIA! Work in progress!");
                }
                if ((Keys)vkCode == Keys.NumPad8) // Numpad "8" Announce MID MIA to your team!
                {
                    //MessageBox.Show("MID MIA! Work in progress!");
                }
                if ((Keys)vkCode == Keys.NumPad9) // Numpad "9" Announce BOT MIA to your team!
                {
                    //MessageBox.Show("BOT MIA! Work in progress!");
                }
                if ((Keys)vkCode == Keys.Decimal) // Numpad "Del" Announce timers to your team!
                {
                    //MessageBox.Show("ACTIVE TIMERS! Work in progress!");
                }
            }
            return CallNextHookEx(_hookID, nCode, wParam, lParam);
        }

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr SetWindowsHookEx(int idHook,
            LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool UnhookWindowsHookEx(IntPtr hhk);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
            IntPtr wParam, IntPtr lParam);

        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr GetModuleHandle(string lpModuleName);

    }
}
